//
//  YHTextAttachment.swift
//  EmotionKeyboard
//
//  Created by 昱含 on 16/6/1.
//  Copyright © 2016年 YuHan. All rights reserved.
//

import UIKit

class YHTextAttachment: NSTextAttachment {
    
    var chs: String?
    
    class func emotionImageToImageText(em: YHEmotions, font: UIFont) -> NSAttributedString{
        let attachment = YHTextAttachment()
        attachment.image = UIImage(contentsOfFile: em.imagePath ?? "")
        attachment.chs = em.chs
        let lineHeight = font.lineHeight ?? 0
        attachment.bounds = CGRect(x: 0, y: -4, width: lineHeight, height: lineHeight)
        let imageText = NSMutableAttributedString(attributedString: NSAttributedString(attachment: attachment))
        imageText.addAttributes([NSFontAttributeName : font], range: NSMakeRange(0, 1))
        return imageText
    
    }
    
}
